<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.20"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libxlsxwriter: Getting Started with libxlsxwriter</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">libxlsxwriter
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.20 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="PageDoc"><div class="header">
  <div class="headertitle">
<div class="title">Getting Started with libxlsxwriter </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#gsg_linux">Installation on Linux</a><ul><li class="level2"><a href="#gsg_quick_start">Quick-start on Linux</a></li>
<li class="level2"><a href="#gsg_dependencies">Install the dependencies</a></li>
<li class="level2"><a href="#gsg_git">Get the source code via Git</a></li>
<li class="level2"><a href="#gsg_tarball">Get the source code as a tarball</a></li>
<li class="level2"><a href="#gsg_build">Build the source code</a></li>
<li class="level2"><a href="#gsg_examples">Try an example</a></li>
<li class="level2"><a href="#gsg_install">Install the library</a></li>
<li class="level2"><a href="#gsg_using">Using the library</a></li>
</ul>
</li>
<li class="level1"><a href="#gsg_bsd">Installation on FreeBSD and OpenBSD</a></li>
<li class="level1"><a href="#gsg_macos">Installation on macOS and iOS</a><ul><li class="level2"><a href="#gsg_cocoapods">Install using Cocoa Pods for Xcode</a></li>
<li class="level2"><a href="#gsg_brew">Installation on macOS with homebrew</a></li>
</ul>
</li>
<li class="level1"><a href="#gsg_cmake">Install using CMake</a><ul><li class="level2"><a href="#gsg_cmake_flags">CMake Flags</a></li>
<li class="level2"><a href="#gsg_cmake_options">CMake Options</a></li>
<li class="level2"><a href="#gsg_cmake_generators">CMake Generators</a></li>
<li class="level2"><a href="#gsg_cmake_app">Cmake for Microsoft Visual Studio</a></li>
</ul>
</li>
<li class="level1"><a href="#gsg_vcpkg">Using libxlsxwriter in Microsoft Visual Studio via vcpkg</a></li>
<li class="level1"><a href="#gsg_tmpdir">Specifying a TEMP directory for libxlsxwriter</a></li>
<li class="level1"><a href="#gsg_ming">Installation on Windows using Mingw-w64 and MSYS2</a></li>
<li class="level1"><a href="#gsg_qt">Installation in Qt-Creator for Windows</a></li>
<li class="level1"><a href="#gsg_minizip">Linking against system minizip</a></li>
<li class="level1"><a href="#gsg_endian">Compiling on Big Endian Architecture</a></li>
<li class="level1"><a href="#gsg_next">Next steps</a></li>
</ul>
</div>
<div class="textblock"><p>Here are some instructions to get you up and running with the libxlsxwriter library on different OSes.</p>
<h1><a class="anchor" id="gsg_linux"></a>
Installation on Linux</h1>
<h2><a class="anchor" id="gsg_quick_start"></a>
Quick-start on Linux</h2>
<p>If you prefer to assemble Ikea furniture first and only read the instructions when you have parts left over then the following minimal set of commands should get you up and running on a Debian like system: </p><pre class="fragment">sudo apt-get install -y zlib1g-dev
git clone https://github.com/jmcnamara/libxlsxwriter.git
cd libxlsxwriter
make
sudo make install
</pre><p>If you read instructions first and then assemble the furniture you will know how to proceed.</p>
<h2><a class="anchor" id="gsg_dependencies"></a>
Install the dependencies</h2>
<p>The only dependency (apart from <a class="el" href="running_the_tests.html">testing dependencies</a>) is <a href="http://www.zlib.net">Zlib</a> version &gt;= 1.2.8.</p>
<p>The easiest way to install <code>zlib</code> is from the source code: </p><pre class="fragment">curl -O -L  http://www.zlib.net/zlib-1.2.11.tar.gz
tar zxf zlib-1.2.11.tar.gz
cd zlib-1.2.11

./configure
make

sudo make install
</pre><p>Alternatively, you can use your OS packager to install the <code>zlib</code> development libraries. For example: </p><pre class="fragment">sudo apt-get install -y zlib1g-dev
</pre><p>However, you need to ensure that the version installed is &gt;= 1.2.8 or you will get zlib related compilation issues.</p>
<h2><a class="anchor" id="gsg_git"></a>
Get the source code via Git</h2>
<p>Clone the libxlsxwriter source code repository from GitHub as follows: </p><pre class="fragment">git clone https://github.com/jmcnamara/libxlsxwriter.git
# Or use your preferred protocol instead of https.
</pre><h2><a class="anchor" id="gsg_tarball"></a>
Get the source code as a tarball</h2>
<p>If you prefer you can get a tarball of the latest code as follows: </p><pre class="fragment">curl -O -L http://github.com/jmcnamara/libxlsxwriter/archive/master.tar.gz
</pre><h2><a class="anchor" id="gsg_build"></a>
Build the source code</h2>
<p>Build the source code as follows: </p><pre class="fragment">cd libxlsxwriter
make
</pre><p>This will create a static and dynamic library in the local <code>./lib</code> directory: </p><pre class="fragment">ls lib
libxlsxwriter.a     libxlsxwriter.so
</pre><p>To see a verbose summary of the compilation steps use <code>V=1</code>: </p><pre class="fragment">make V=1
</pre><h2><a class="anchor" id="gsg_examples"></a>
Try an example</h2>
<p>If there weren't any warnings or errors in the previous step (and there shouldn't have been) then you can build the programs in the <code>examples</code> directory and try one of them out: </p><pre class="fragment">make examples
./examples/hello
</pre><p>This will create a <code>hello_world.xlsx</code> file in your current directory. Open the file in a spreadsheet application. The output should look like this: </p><div class="image">
<img src="hello01.png" alt=""/>
</div>
<p>There is a large range of tests that you can run but they have some additional dependencies. If you are interested see <a class="el" href="running_the_tests.html">Running the Test Suite</a>.</p>
<h2><a class="anchor" id="gsg_install"></a>
Install the library</h2>
<p>Libxlsxwriter supports a simplified installation scheme for a static and dynamic/shared library and header files. </p><pre class="fragment">sudo make install
</pre><p>The files are installed to <code>/usr/local</code> by default but this can be overridden by using the <code>PREFIX</code> environmental variable: </p><pre class="fragment">make install PREFIX=/usr/third_party
</pre><p>A staging directory can be set with <code>DESTDIR</code> which is prepended to all install paths, a feature mostly useful for packaging: </p><pre class="fragment">make install PREFIX=/usr/third_party DESTDIR=./staging/
</pre><p>This would build and link the code with <code>/usr/third_party</code> as the installation location but actually install to <code>./staging/usr/third_party</code>.</p>
<p>This installation method isn't fool proof but if it fails on your system you will probably know exactly how to fix it or have no idea how to fix it. I'm hoping for the former.</p>
<h2><a class="anchor" id="gsg_using"></a>
Using the library</h2>
<p>Using you favourite editor create a file like the following called <code>myexcel.c</code>:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;xlsxwriter.h&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line"> </div>
<div class="line">    <a class="code" href="structlxw__workbook.html">lxw_workbook</a>  *workbook  = <a class="code" href="workbook_8h.html#a1cf96608a23ee4eb0e8467c15240d00b">workbook_new</a>(<span class="stringliteral">&quot;myexcel.xlsx&quot;</span>);</div>
<div class="line">    <a class="code" href="structlxw__worksheet.html">lxw_worksheet</a> *worksheet = <a class="code" href="workbook_8h.html#a81d456b4f65a464e78e4a0030ecc3c2e">workbook_add_worksheet</a>(workbook, NULL);</div>
<div class="line">    <span class="keywordtype">int</span> row = 0;</div>
<div class="line">    <span class="keywordtype">int</span> col = 0;</div>
<div class="line"> </div>
<div class="line">    <a class="code" href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a>(worksheet, row, col, <span class="stringliteral">&quot;Hello me!&quot;</span>, NULL);</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">return</span> <a class="code" href="workbook_8h.html#ad9e7aeebc0fd43562db5bcd527b2ee5e">workbook_close</a>(workbook);</div>
<div class="line">}</div>
</div><!-- fragment --><p>If you executed the <code>"make install"</code> command in the previous section then you should be able to compile the program as follows: </p><pre class="fragment">cc myexcel.c -o myexcel -lxlsxwriter
</pre><p>In some environments, or if you changed the <code>PREFIX</code> location, you may have to provide explicit <code>include</code> and <code>lib</code> paths: </p><pre class="fragment">cc myexcel.c -o myexcel -I/usr/local/include -L/usr/local/lib -lxlsxwriter
</pre><p>This will create an executable that you can run to generate an Excel spreadsheet: </p><pre class="fragment">./myexcel
xdg-open myexcel.xlsx
</pre><p>If the installation didn't work for you then you can link against the static library you created in the "Build the source code" step: </p><pre class="fragment">cc myexcel.c -o myexcel -I /path/to/libxlsxwriter/include \
                           /path/to/libxlsxwriter/lib/libxlsxwriter.a -lz
</pre><h1><a class="anchor" id="gsg_bsd"></a>
Installation on FreeBSD and OpenBSD</h1>
<p>Installation on FreeBSD and OpenBSD is mainly the same as on Linux, see above, with the differences outlined below.</p>
<p>Both FreeBSD and OpenBSD come with the zlib development libraries pre-installed so there are no additional dependencies. However, if you have any issues then follow the instructions <a class="el" href="getting_started.html#gsg_dependencies">to install zlib</a>.</p>
<p><a class="el" href="getting_started.html#gsg_git">Get the source code via Git</a> or <a class="el" href="getting_started.html#gsg_tarball">get the source code as a tarball</a> as shown above then build the source code as follows using <code>gmake</code> (not make): </p><pre class="fragment">cd libxlsxwriter
gmake
</pre><p>Then follow the instructions in the Linux section to <a class="el" href="getting_started.html#gsg_install">install the library</a> and <a class="el" href="getting_started.html#gsg_using">use the library</a>.</p>
<h1><a class="anchor" id="gsg_macos"></a>
Installation on macOS and iOS</h1>
<p>The instructions for installing on Linux, shown above, will also work on macOS.</p>
<p>To install for Xcode and iOS use the Cocoa Pods method shown in the next section.</p>
<p>On macOS you can also use <a href="https://brew.sh">brew/homebrew</a>, see below.</p>
<h2><a class="anchor" id="gsg_cocoapods"></a>
Install using Cocoa Pods for Xcode</h2>
<p>For iOS and macOS projects in Xcode you can install libxlsxwriter using <a href="https://cocoapods.org">CocoaPods</a>.</p>
<p>Add the following entry to your <code>Podfile</code>: </p><pre class="fragment">pod 'libxlsxwriter', '~&gt; 0.9'
</pre><p>if you are using Swift, you can now add an import: </p><pre class="fragment">import xlsxwriter
</pre><p>And call its C functions like this: </p><pre class="fragment">let documentDirectory = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:false)
let fileURL = documentDirectory.appendingPathComponent("hello_world.xlsx")

let workbook = workbook_new((fileURL.absoluteString.dropFirst(6) as NSString).fileSystemRepresentation)
let worksheet = workbook_add_worksheet(workbook, nil)
worksheet_write_string(worksheet, 0, 0, "Hello", nil)
worksheet_write_number(worksheet, 1, 0, 123, nil)
workbook_close(workbook)
</pre><p>For a sample Xcode project that uses the libxlsxwriter cocoapod for iOS and macOS with Objective-C and Swift see <a href="https://github.com/lrossi/libxlsxwriterCocoaExamples">libxlsxwriter Cocoa Examples</a> or <a href="https://github.com/FrankenApps/LibXlsxWriterSwiftSample">LibXlsxWriterSwiftSample</a> for an updated example for Swift 5.</p>
<h2><a class="anchor" id="gsg_brew"></a>
Installation on macOS with homebrew</h2>
<p>On macOS you can also use <a href="https://brew.sh">brew/homebrew</a>: </p><pre class="fragment">brew install libxlsxwriter
</pre><p>Once installed you can compile and run a libxlsxwriter program as follows: </p><pre class="fragment">cc myexcel.c -o myexcel -I/usr/local/include -L/usr/local/lib -lxlsxwriter
./myexcel
</pre><h1><a class="anchor" id="gsg_cmake"></a>
Install using CMake</h1>
<p>Libxlsxwriter also supports <a href="https://cmake.org">CMake</a> for building and installing the library, as follows: </p><pre class="fragment">cmake $SOURCE_DIR $FLAGS
</pre><p>For example: </p><pre class="fragment">cd cmake
cmake ..
make
make install
</pre><h2><a class="anchor" id="gsg_cmake_flags"></a>
CMake Flags</h2>
<p>Certain build features can be controlled by passing flags to Cmake. For example: </p><pre class="fragment">cd cmake
cmake .. -DBUILD_TESTS=ON
make

# Run the unit tests.
./xlsxwriter_unit
</pre><p>Some of the Libxlsxwriter specific flags are:</p>
<ul>
<li><code>BUILD_STATIC</code>: Build static libraries (default on). To build shared libraries, pass <code>-DBUILD_STATIC=OFF</code> during configuration.</li>
<li><code>BUILD_EXAMPLES</code>: Build example files (default off). To build the examples, pass <code>-DBUILD_EXAMPLES=ON</code> during configuration.</li>
<li><code>BUILD_TESTS</code>: Build unittests (default off). To build the unittests, pass <code>-DBUILD_TESTS=ON</code> during configuration.</li>
<li><code>ZLIB_ROOT</code>: The ZLIB root directory can be specified either through an environment variable (<code>export ZLIB_ROOT=/usr/include</code>) or using a flag with CMake (<code>-DZLIB_ROOT:STRING=/usr/include</code>). This sets the preferred search path for the ZLIB installation.</li>
</ul>
<h2><a class="anchor" id="gsg_cmake_options"></a>
CMake Options</h2>
<p>CMake sets debug and release builds with the <code>CMAKE_BUILD_TYPE</code> option. To build in release mode, pass <code>-DCMAKE_BUILD_TYPE=Release</code> during configuration.</p>
<h2><a class="anchor" id="gsg_cmake_generators"></a>
CMake Generators</h2>
<p>CMake also supports custom build generators, such as Makefiles, Ninja, Visual Studio, and Xcode. For example, to generate a Visual Studio solution, configure with: </p><pre class="fragment">cmake .. -G "Visual Studio 14 2015 Win64"
</pre><p>For more information on using generators see: <a href="https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html">cmake-generators</a>.</p>
<h2><a class="anchor" id="gsg_cmake_app"></a>
Cmake for Microsoft Visual Studio</h2>
<p>You can also use Cmake to build a Microsoft Visual Studio (although see also the next section on using vcpkg which is less manual).</p>
<p>Open a Windows CMD or Command Window and set up your MSVC environment, if required.</p>
<p>Then create a work directory and and an install directory that the include and library files will be installed to. Set the follow variables to point to the directories: </p><pre class="fragment">set    WORK_DIR=C:/Users/Username/tmp
set INSTALL_DIR=C:/Users/Username/tmp/install_dir
</pre><p>Build the Zlib library: </p><pre class="fragment">cd %WORK_DIR%

git clone https://github.com/madler/zlib.git
cd zlib
mkdir build
cd    build

cmake .. -G "Visual Studio 14 Win64" -DCMAKE_INSTALL_PREFIX:PATH="%INSTALL_DIR%/zlib"

cmake --build . --config Release --target install
</pre><p>Build the libxlsxwriter library: </p><pre class="fragment">cd %WORK_DIR%

git clone https://github.com/jmcnamara/libxlsxwriter.git
cd libxlsxwriter
mkdir build
cd    build

cmake .. -G "Visual Studio 14 Win64" -DCMAKE_INSTALL_PREFIX:PATH="%INSTALL_DIR%/libxlsxwriter" -DZLIB_ROOT:STRING="%INSTALL_DIR%/zlib"

cmake --build . --config Release --target install
</pre><p>Create a new Win32 Console (or other C/C++) application in Visual Studio: </p><pre class="fragment">File
  -&gt; New
    -&gt; Project

Visual C++
  -&gt; Win32
    -&gt; Win32 Console Application
</pre><p>Change the ARCH in the main Dialog to "x64" and the Configuration to "Release" (or to match the parameter to cmake).</p>
<p>Replace the empty main with a libxlsxwriter example from the distro. Make sure to include "stdafx.h" and "xlsxwriter.h":</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;stdafx.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;xlsxwriter.h&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line"> </div>
<div class="line">    <a class="code" href="structlxw__workbook.html">lxw_workbook</a>  *workbook = <a class="code" href="workbook_8h.html#a1cf96608a23ee4eb0e8467c15240d00b">workbook_new</a>(<span class="stringliteral">&quot;hello_world.xlsx&quot;</span>);</div>
<div class="line">    <a class="code" href="structlxw__worksheet.html">lxw_worksheet</a> *worksheet = <a class="code" href="workbook_8h.html#a81d456b4f65a464e78e4a0030ecc3c2e">workbook_add_worksheet</a>(workbook, NULL);</div>
<div class="line"> </div>
<div class="line">    <a class="code" href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a>(worksheet, 0, 0, <span class="stringliteral">&quot;Hello&quot;</span>, NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, 1, 0, 123, NULL);</div>
<div class="line"> </div>
<div class="line">    <a class="code" href="workbook_8h.html#ad9e7aeebc0fd43562db5bcd527b2ee5e">workbook_close</a>(workbook);</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --><p>Edit the application properties: </p><pre class="fragment">Project
  -&gt; ConsoleApplication Properties
</pre><p>Set the libxlsxwriter include path to match the path used above: </p><pre class="fragment">Configuration Properties
  -&gt; C/C++
    -&gt; General
      -&gt; Additional Include Directories

Set it to the following (or similar path used above):

C:\Users\Username\tmp\install_dir\libxlsxwriter\include
</pre><p>Set the linker directories to match the path created above: </p><pre class="fragment">Configuration Properties
  -&gt; Linker
    -&gt; General
      -&gt; Additional Library Directories

Add the following (or similar paths used above):

C:\Users\Username\tmp\install_dir\libxlsxwriter\lib\x64\Release
C:\Users\Username\tmp\install_dir\zlib\lib
</pre><p>Set the linker additional libraries to match the zlib and xlsxwriter libs created above: </p><pre class="fragment">Configuration Properties
  -&gt; Linker
     -&gt; Input
        -&gt; Additional Dependencies

Add the following:

xlsxwriter.lib
zlib.lib
</pre><p>Build the solution and run the output executable. It should create a hello_world.xlsx file in the same directory you ran it from.</p>
<h1><a class="anchor" id="gsg_vcpkg"></a>
Using libxlsxwriter in Microsoft Visual Studio via vcpkg</h1>
<p>A convenient way to get the latest release version of libxlsxwriter and integrate it into your Visual Studio build environment is to use the <a href="https://docs.microsoft.com/en-us/cpp/build/vcpkg?view=vs-2019">vcpkg</a> tool. This uses the CMake build system shown in the previous section but with less user interaction. From the vcpkg docs:</p>
<blockquote class="doxtable">
<p>"vcpkg" is a command-line package manager that greatly simplifies the acquisition and installation of third-party libraries on Windows, Linux and MacOS. If your project uses third-party libraries, we recommend that you use vcpkg to install them. vcpkg supports both open-source and proprietary libraries. All libraries in the vcpkg Windows catalog have been tested for compatibility with Visual Studio 2015, Visual Studio 2017, and Visual Studio 2019. </p>
</blockquote>
<p>Install vcpkg and libxlsxwriter as follows in Windows CMD or Powershell: </p><pre class="fragment">&gt; git clone https://github.com/microsoft/vcpkg.git
&gt; bootstrap-vcpkg.bat
&gt; vcpkg install libxlsxwriter
</pre><p>You should then see libxlsxwriter installed as follows (note that the required zlib dependency has also been installed): </p><pre class="fragment">&gt; vcpkg list
libxlsxwriter:x86-windows  0.8.6-1   Libxlsxwriter is a C library that ...
zlib:x86-windows           1.2.11-5  A compression library
</pre><p>You can also install libxlsxwriter for other build targets like <code>x64</code> </p><pre class="fragment">&gt; vcpkg install libxlsxwriter:x64-windows

&gt; vcpkg list
libxlsxwriter:x64-windows  0.8.6-1   Libxlsxwriter is a C library that ...
libxlsxwriter:x86-windows  0.8.6-1   Libxlsxwriter is a C library that ...
zlib:x64-windows           1.2.11-5  A compression library
zlib:x86-windows           1.2.11-5  A compression library
</pre><p>To use libxlsxwriter from within Visual Studio you can "integrate" it into your environment: </p><pre class="fragment">&gt; vcpkg integrate install
Applied user-wide integration for this vcpkg root.
</pre><p>All MSBuild C projects can now include libxlsxwriter directly. Linking will also be handled automatically. For example, create a new Win32 Console (or other C/C++) application in Visual Studio: </p><pre class="fragment">File
  -&gt; New
    -&gt; Project

Visual C++
  -&gt; Win32
    -&gt; Win32 Console Application
</pre><p>Replace the empty main with a libxlsxwriter example from the distro. Make sure to include "stdafx.h" and "xlsxwriter.h":</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;stdafx.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;xlsxwriter.h&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line"> </div>
<div class="line">    <a class="code" href="structlxw__workbook.html">lxw_workbook</a>  *workbook = <a class="code" href="workbook_8h.html#a1cf96608a23ee4eb0e8467c15240d00b">workbook_new</a>(<span class="stringliteral">&quot;hello_world.xlsx&quot;</span>);</div>
<div class="line">    <a class="code" href="structlxw__worksheet.html">lxw_worksheet</a> *worksheet = <a class="code" href="workbook_8h.html#a81d456b4f65a464e78e4a0030ecc3c2e">workbook_add_worksheet</a>(workbook, NULL);</div>
<div class="line"> </div>
<div class="line">    <a class="code" href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a>(worksheet, 0, 0, <span class="stringliteral">&quot;Hello&quot;</span>, NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, 1, 0, 123, NULL);</div>
<div class="line"> </div>
<div class="line">    <a class="code" href="workbook_8h.html#ad9e7aeebc0fd43562db5bcd527b2ee5e">workbook_close</a>(workbook);</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --><p>Change the target to "Release" and the architecture to "x86" (or whatever you installed above). You can now "Build Solution". The resulting executable will be put in the output directory with the required "xlsxwriter.dll" and "zlib1.dll" files.</p>
<h1><a class="anchor" id="gsg_tmpdir"></a>
Specifying a TEMP directory for libxlsxwriter</h1>
<p>The libxlsxwriter library creates temporary files in the system <code>TEMP</code> directory during assembly of an xlsx file. On Windows this directory may not be writeable by a libxlsxwriter application (although it will try several <code>TEMP</code> locations before returning an error). To work around this you can set the <code>tmpdir</code> parameter of the <a class="el" href="structlxw__workbook__options.html" title="Workbook options.">lxw_workbook_options</a> struct and pass it to <code><a class="el" href="workbook_8h.html#a8ca9bd8c30c618b81ca6180f78b03323" title="Create a new workbook object, and set the workbook options.">workbook_new_opt()</a></code>:</p>
<div class="fragment"><div class="line"><a class="code" href="structlxw__workbook__options.html">lxw_workbook_options</a> options = {.constant_memory = <a class="code" href="common_8h.html#a57bffaf0ff3cb4e9f4f7f2b0b6dad349a847f574cc183a1d8a4e3800fe28091f4">LXW_FALSE</a>,</div>
<div class="line">                                .tmpdir = <span class="stringliteral">&quot;C:\\Temp&quot;</span>};</div>
<div class="line"> </div>
<div class="line"><a class="code" href="structlxw__workbook.html">lxw_workbook</a>  *workbook  = <a class="code" href="workbook_8h.html#a8ca9bd8c30c618b81ca6180f78b03323">workbook_new_opt</a>(<span class="stringliteral">&quot;filename.xlsx&quot;</span>, &amp;options);</div>
</div><!-- fragment --><p>This can also be used on Unix systems where the <code>TEMP</code> directory isn't writeable.</p>
<p>The TEMP file handling with optional temporary directory support is provided by the <a href="http://www.di-mgt.com.au/c_function_to_create_temp_file.html">Tmpfileplus</a> library which is included in the source tree. If you wish to use the standard library <code>tmpfile()</code> function instead you can compile without <code>tmpfileplus</code> as follows: </p><pre class="fragment">make USE_STANDARD_TMPFILE=1
</pre><dl class="section note"><dt>Note</dt><dd>When using the the standard library <code>tmpfile()</code> the <code>tmpdir</code> parameter, shown above, is ignored.</dd></dl>
<h1><a class="anchor" id="gsg_ming"></a>
Installation on Windows using Mingw-w64 and MSYS2</h1>
<p>The libxlsxwriter library can also be compiled on Windows using the <a href="http://mingw-w64.org/doku.php">Mingw-w64</a> "Minimalist GNU for Windows" toolchain. These tools can be run from the Windows <code>cmd.exe</code> but it is recommended to use the <a href="http://msys2.github.io">MSYS2</a> "Minimal System" Bourne Shell.</p>
<p>Here are some instructions on how to compile libxlsxwriter with Mingw-w64 and MSYS2: </p><pre class="fragment"># Install MSYS2 64 or 32 bit from http://msys2.github.io/

# Install the dev tools for libxlsxwriter.
pacman -S git gcc make zlib-devel

# Clone and build libxlsxwriter.
git clone https://github.com/jmcnamara/libxlsxwriter.git
cd libxlsxwriter/
make
</pre><p>After compilation you can follow the instructions in the <a class="el" href="getting_started.html#gsg_install">Install the library</a> and <a class="el" href="getting_started.html#gsg_using">Using the library</a> sections above. When using the library you may also need to link against the zlib library using <code>-lz</code>: </p><pre class="fragment">gcc myexcel.c -o myexcel -lxlsxwriter -lz
</pre><p>It is also possible to use <a href="https://cygwin.com">Cygwin</a> and the older <a href="http://mingw.org">MinGW and MSYS</a>. Libxlsxwriter has been confirmed to compile and work in all of these environments.</p>
<p>See also <a class="el" href="getting_started.html#gsg_tmpdir">Specifying a TEMP directory for libxlsxwriter</a>.</p>
<h1><a class="anchor" id="gsg_qt"></a>
Installation in Qt-Creator for Windows</h1>
<p>The following external guide shows how to <a href="https://github.com/jmcnamara/libxlsxwriter/issues/270">Build libxlsxwriter inside Qt-Creator for Windows</a> with step by step instructions.</p>
<h1><a class="anchor" id="gsg_minizip"></a>
Linking against system minizip</h1>
<p>Libxlsxwriter uses the <code>minizip</code> component of <a href="http://www.zlib.net">Zlib</a> to create the xlsx zip file container. The source files for <code>minizip</code> are included in the src tree of libxlsxwriter and are statically linked by default.</p>
<p>If you have a <code>lminizip</code> library already installed on your system and prefer to dynamically link against that you can use the following compilation option: </p><pre class="fragment">make USE_SYSTEM_MINIZIP=1
</pre><h1><a class="anchor" id="gsg_endian"></a>
Compiling on Big Endian Architecture</h1>
<p>Libxlsxwriter can be compiled on a big endian system as follows: </p><pre class="fragment">make USE_BIG_ENDIAN=1
</pre><h1><a class="anchor" id="gsg_next"></a>
Next steps</h1>
<p>If you got libxlsxwriter built and working successfully then the next sections will look at how to create some more in-depth examples.</p>
<p>Next: <a class="el" href="tutorial01.html">Tutorial 1: Create a simple XLSX file</a> </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
<div class="ttc" id="aworkbook_8h_html_ad9e7aeebc0fd43562db5bcd527b2ee5e"><div class="ttname"><a href="workbook_8h.html#ad9e7aeebc0fd43562db5bcd527b2ee5e">workbook_close</a></div><div class="ttdeci">lxw_error workbook_close(lxw_workbook *workbook)</div><div class="ttdoc">Close the Workbook object and write the XLSX file.</div></div>
<div class="ttc" id="astructlxw__workbook__options_html"><div class="ttname"><a href="structlxw__workbook__options.html">lxw_workbook_options</a></div><div class="ttdoc">Workbook options.</div><div class="ttdef"><b>Definition:</b> workbook.h:254</div></div>
<div class="ttc" id="acommon_8h_html_a57bffaf0ff3cb4e9f4f7f2b0b6dad349a847f574cc183a1d8a4e3800fe28091f4"><div class="ttname"><a href="common_8h.html#a57bffaf0ff3cb4e9f4f7f2b0b6dad349a847f574cc183a1d8a4e3800fe28091f4">LXW_FALSE</a></div><div class="ttdeci">@ LXW_FALSE</div><div class="ttdef"><b>Definition:</b> common.h:51</div></div>
<div class="ttc" id="aworkbook_8h_html_a1cf96608a23ee4eb0e8467c15240d00b"><div class="ttname"><a href="workbook_8h.html#a1cf96608a23ee4eb0e8467c15240d00b">workbook_new</a></div><div class="ttdeci">lxw_workbook * workbook_new(const char *filename)</div><div class="ttdoc">Create a new workbook object.</div></div>
<div class="ttc" id="aworkbook_8h_html_a8ca9bd8c30c618b81ca6180f78b03323"><div class="ttname"><a href="workbook_8h.html#a8ca9bd8c30c618b81ca6180f78b03323">workbook_new_opt</a></div><div class="ttdeci">lxw_workbook * workbook_new_opt(const char *filename, lxw_workbook_options *options)</div><div class="ttdoc">Create a new workbook object, and set the workbook options.</div></div>
<div class="ttc" id="astructlxw__worksheet_html"><div class="ttname"><a href="structlxw__worksheet.html">lxw_worksheet</a></div><div class="ttdoc">Struct to represent an Excel worksheet.</div><div class="ttdef"><b>Definition:</b> worksheet.h:1603</div></div>
<div class="ttc" id="astructlxw__workbook_html"><div class="ttname"><a href="structlxw__workbook.html">lxw_workbook</a></div><div class="ttdoc">Struct to represent an Excel workbook.</div><div class="ttdef"><b>Definition:</b> workbook.h:273</div></div>
<div class="ttc" id="aworksheet_8h_html_ac208046e7a6d12cc87982422efa41b31"><div class="ttname"><a href="worksheet_8h.html#ac208046e7a6d12cc87982422efa41b31">worksheet_write_string</a></div><div class="ttdeci">lxw_error worksheet_write_string(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, const char *string, lxw_format *format)</div><div class="ttdoc">Write a string to a worksheet cell.</div></div>
<div class="ttc" id="aworksheet_8h_html_ad9fc47d3beaa2ab4759414e8580c2289"><div class="ttname"><a href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a></div><div class="ttdeci">lxw_error worksheet_write_number(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, double number, lxw_format *format)</div><div class="ttdoc">Write a number to a worksheet cell.</div></div>
<div class="ttc" id="aworkbook_8h_html_a81d456b4f65a464e78e4a0030ecc3c2e"><div class="ttname"><a href="workbook_8h.html#a81d456b4f65a464e78e4a0030ecc3c2e">workbook_add_worksheet</a></div><div class="ttdeci">lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)</div><div class="ttdoc">Add a new worksheet to a workbook.</div></div>
<!-- HTML footer for doxygen 1.8.20-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Copyright 2014-2020 John McNamara.
Generated by&#160;<a href="http://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.20
</small></address>
</body>
</html>
